package com.yxs.school.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yxs.school.api.entity.Focus;
import com.yxs.school.api.service.IFocusService;
import com.yxs.school.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 关注 前端控制器
 * </p>
 *
 * @author whp
 * @since 2019-11-15
 */
@RestController
@RequestMapping("/api/focus")
public class FocusController {
    @Resource
    private IFocusService iFocusService;
    @PostMapping("save")
    public R save(@RequestBody Focus focus) {
        boolean flag = iFocusService.save(focus);
        if (flag) {
            return R.data(200,null,"成功");
        }else {
            return R.fail(400,"失败");
        }
    }
    @PostMapping("update")
    @PutMapping("update")
    public R update(@RequestBody Focus focus) {
        boolean flag = iFocusService.updateById(focus);
        if (flag ){
            return R.data(200,null,"成功");
        }else {
            return R.fail(400,"失败");
        }
    }
    @PostMapping("delete")
    @DeleteMapping("delete")
    public R delete(@RequestBody List<Integer> ids) {
        boolean flag =iFocusService.removeByIds(ids);
        if (flag ){
            return R.data(200,null,"成功");
        }else {
            return R.fail(400,"失败");
        }
    }
    @PostMapping("deleteOne")
    @DeleteMapping("deleteOne")
    public R deleteOne(Integer id) {
        boolean flag =iFocusService.removeById(id);
        if (flag ){
            return R.data(200,null,"成功");
        }else {
            return R.fail(400,"失败");
        }
    }
    @GetMapping("list")
    public R list(Integer articleId,Integer focusId) {
        List<Focus> list= iFocusService.list(new QueryWrapper<Focus>().eq("article_id",articleId)
                .like("focus_id",focusId)
        );
        return R.data(200,list,"成功");
    }
}
